﻿@inherits BaseComponent
@typeparam TItem
@attribute [CascadingTypeParameter(nameof(TItem))]

@namespace FluentCMS.Web.UI.Components

@if (Visible)
{
    <div class="@this.ClassName("DataTableWrapper")">
        <table class="@this.GetClasses()" @attributes="AdditionalAttributes">
            <thead class="@this.ClassName("DataTableHead")">
                <tr class="@this.ClassName("DataTableRow")">
                    <CascadingValue Value="true" Name="DataTableColumnHeader" IsFixed="true">
                        @ChildContent
                    </CascadingValue>
                </tr>
            </thead>
            <tbody class="@this.ClassName("DataTableBody")">
                @if (Items != null)
                {
                    foreach (var item in Items)
                    {
                        <tr @onclick="() => HandleRowClick(item)" class="@this.ClassName("DataTableRow")" @key="item">
                            <CascadingValue Value="@item" IsFixed="true">
                                <CascadingValue Value="false" Name="DataTableColumnHeader">
                                    @ChildContent
                                </CascadingValue>
                            </CascadingValue>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
}